package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.system.domain.ZhGameInfo;
import com.ruoyi.system.service.IZhGameInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ZhGameArea;
import com.ruoyi.system.service.IZhGameAreaService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.service.IZhDeptInfoService;
import com.ruoyi.common.domain.ZhDeptInfo;

/**
 * 游戏区服 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-05-05
 */
@Controller
@RequestMapping("/system/zhGameArea")
public class ZhGameAreaController extends BaseController
{
    private String prefix = "system/zhGameArea";

	@Autowired
	private IZhGameAreaService zhGameAreaService;

	@Autowired
	private IZhDeptInfoService zhDeptInfoService;

	@Autowired
	private IZhGameInfoService zhGameInfoService;

	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhGameArea:view")
	@GetMapping("/{gameId}")
	public String zhGameArea(ZhGameArea zhGameArea,ModelMap mmap,@PathVariable("gameId")int gameId)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhGameArea.getParams())));

		zhGameArea.setGameId(gameId);
		mmap.put("zhGameInfos" , zhGameInfoService.selectZhGameInfoList(buildParamsContainer(ZhGameInfo.class,zhGameArea.getParams())));

		return prefix + "/zhGameArea";
	}
	
	/**
	 * 查询游戏区服列表
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhGameArea:list")
	@RequestMapping(value = "/list",method = {RequestMethod.POST,RequestMethod.GET})
	@ResponseBody
	public TableDataInfo list(ZhGameArea zhGameArea)
	{
		startPage();
        List<ZhGameArea> list = zhGameAreaService.selectZhGameAreaList(zhGameArea);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出游戏区服列表
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhGameArea:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZhGameArea zhGameArea)
    {
    	List<ZhGameArea> list = zhGameAreaService.selectZhGameAreaList(zhGameArea);
        ExcelUtil<ZhGameArea> util = new ExcelUtil<ZhGameArea>(ZhGameArea.class);
        return util.exportExcel(list, "zhGameArea");
    }
	
	/**
	 * 新增游戏区服
	 */
	@RequiresPermissions("system:zhGameArea:add")
	@DataScope(tableAlias = "l")
	@GetMapping("/add")
	public String add(ZhGameArea zhGameArea,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhGameArea.getParams())));
		mmap.put("zhGameInfos" , zhGameInfoService.selectZhGameInfoList(buildParamsContainer(ZhGameInfo.class,zhGameArea.getParams())));

		mmap.put("zhGameRootAreas" , zhGameAreaService.selectRootZhGameAreaList(zhGameArea));

		return prefix + "/add";
	}
	
	/**
	 * 新增保存游戏区服
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhGameArea:add")
	@Log(title = "游戏区服", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ZhGameArea zhGameArea)
	{		
		return toAjax(zhGameAreaService.insertZhGameArea(zhGameArea));
	}

	/**
	 * 修改游戏区服
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhGameArea:edit")
	@GetMapping("/edit/{id}")
	public String edit(ZhGameArea zhGameArea,@PathVariable("id") Integer id, ModelMap mmap)
	{
		ZhGameArea result = zhGameAreaService.selectZhGameAreaById(id);
		mmap.put("zhGameArea", result);
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhGameArea.getParams())));
		mmap.put("zhGameInfos" , zhGameInfoService.selectZhGameInfoList(buildParamsContainer(ZhGameInfo.class,zhGameArea.getParams())));

		return prefix + "/edit";
	}
	
	/**
	 * 修改保存游戏区服
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhGameArea:edit")
	@Log(title = "游戏区服", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ZhGameArea zhGameArea)
	{		
		return toAjax(zhGameAreaService.updateZhGameArea(zhGameArea));
	}
	
	/**
	 * 删除游戏区服
	 */
	@RequiresPermissions("system:zhGameArea:remove")
	@Log(title = "游戏区服", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(ZhGameArea zhGameArea,String ids)
	{		
		return toAjax(zhGameAreaService.deleteZhGameAreaByIds(ids));
	}


	/**
	 * 树形
	 */
	// @DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhGameArea:view")
	@GetMapping( "treeData/{gameId}")
	@ResponseBody
	public List treeData(ZhGameArea zhGameArea,@PathVariable("gameId")int gameId)
	{
		zhGameArea.setGameId(gameId);
		// List list = zhGameAreaService.selectTree(zhGameArea);
		// return list;
		List<ZhGameArea> list = zhGameAreaService.selectZhGameAreaList(zhGameArea);
		return list;
	}

	@RequiresPermissions("system:zhGameArea:view")
	@GetMapping("tree")
	public String tree(ZhGameArea zhGameArea,ModelMap mmap)
	{
		return prefix + "/tree";
	}

	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhGameArea:view")
	@Log(title = "游戏区服", businessType = BusinessType.DELETE)
	@GetMapping( "rootData")
	@ResponseBody
	public List rootData(ZhGameArea zhGameArea)
	{
		// List list = zhGameAreaService.selectTree(zhGameArea);
		// return list;
		List<ZhGameArea> list = zhGameAreaService.selectRootZhGameAreaList(zhGameArea);
		return list;
	}
}
